package com.yang.spring.events;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;

/**
 * 自定义事件发布者
 */
@Component
public class CustomEventPublisher implements ApplicationEventPublisherAware {
    
    private ApplicationEventPublisher publisher;
    
    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.publisher = applicationEventPublisher;
    }
    
    /**
     * 发布自定义事件
     * @param message 事件消息
     */
    public void publishCustomEvent(String message) {
        System.out.println("发布自定义事件，消息: " + message);
        CustomEvent customEvent = new CustomEvent(this, message);
        publisher.publishEvent(customEvent);
    }
} 